package test.producerconsumer;

import java.util.Random;

public class TaskQueue {

	public static final int MAX_TASKS = 10;

	private Task[] taskQueue = new Task[MAX_TASKS];

	private void takeNap() {
		try {
			Random rand = new Random();
			int sleepTime = rand.nextInt(9) + 1; // 1..10 seconds
			Thread.sleep(sleepTime);
		} catch (InterruptedException e) {
		}
	}

	class Producer extends Thread {
		@Override
		public void run() {
			while (true) {
				takeNap();

				synchronized (taskQueue) {
					if (taskQueue.length == MAX_TASKS) {
						try {
							wait();
						} catch (InterruptedException e) {									
						}
						if (taskQueue.length < MAX_TASKS) {
							Task task = new Task(Task.Action.ADD, "deployTask @" + System.currentTimeMillis());
//							taskQueue.add(task);
						}
					}
				}

			}
		}
	}

	class Consumer extends Thread {
		@Override
		public void run() {

		}
	}

}
